package com.xbongbong.saas.service.impl;

import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.productionorderproduct.pojo.dto.ProductionOrderProductDeleteBatchDTO;
import com.xbongbong.pro.productionorderproduct.pojo.vo.ProductionOrderProductDeleteBatchVO;
import com.xbongbong.saas.model.ProductionOrderProductModel;
import com.xbongbong.saas.service.ProductionOrderProductService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * @author 吴峰
 * @version v1.0
 * @date 2019/3/6 20:54
 * @since v1.0
 */
@Service("productionOrderProductService")
public class ProductionOrderProductServiceImpl implements ProductionOrderProductService {

    private static final Logger LOG = LoggerFactory.getLogger(ProductionOrderProductServiceImpl.class);

    @Resource
    private ProductionOrderProductModel productionOrderProductModel;

    @Override
    public ProductionOrderProductDeleteBatchVO deleteBatch(ProductionOrderProductDeleteBatchDTO productionOrderProductDeleteBatchDTO) throws XbbException {
        ProductionOrderProductDeleteBatchVO productionOrderProductDeleteBatchVO = new ProductionOrderProductDeleteBatchVO();
        try {
            List<Long> productOrderIdIn = productionOrderProductDeleteBatchDTO.getProductOrderIdIn();
            String corpid = productionOrderProductDeleteBatchDTO.getCorpid();
            if (Objects.nonNull(productOrderIdIn) && !productOrderIdIn.isEmpty()) {
                productionOrderProductModel.deleteByProOrderIdIn(productOrderIdIn, corpid);
            }
        } catch (Exception e) {
            LOG.error("ProductionOrderProductServiceImpl.deleteBatch 执行出错：", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        return productionOrderProductDeleteBatchVO;
    }
}
